/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.mime.ParsedDocument;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SaveDocument
/*     */   extends CreateMessage
/*     */ {
/*     */   private String mUuid;
/*     */   private String mFilename;
/*     */   private String mMimeType;
/*     */   private String mAuthor;
/*     */   private MailItem.Type type;
/*     */   private String mDescription;
/*     */   private boolean mDescEnabled;
/*     */   
/*     */   public SaveDocument()
/*     */   {
/*  42 */     this.mOperation = MailboxOperation.SaveDocument;
/*     */   }
/*     */   
/*     */   public SaveDocument(int mailboxId, String digest, long msgSize, int folderId, int flags) {
/*  46 */     super(mailboxId, ":API:", false, digest, msgSize, folderId, true, flags, null);
/*  47 */     this.mOperation = MailboxOperation.SaveDocument;
/*     */   }
/*     */   
/*     */   public String getUuid() {
/*  51 */     return this.mUuid;
/*     */   }
/*     */   
/*     */   public void setUuid(String uuid) {
/*  55 */     this.mUuid = uuid;
/*     */   }
/*     */   
/*     */   public String getFilename() {
/*  59 */     return this.mFilename;
/*     */   }
/*     */   
/*     */   public void setFilename(String filename) {
/*  63 */     this.mFilename = filename;
/*     */   }
/*     */   
/*     */   public String getMimeType() {
/*  67 */     return this.mMimeType;
/*     */   }
/*     */   
/*     */   public void setMimeType(String mimeType) {
/*  71 */     this.mMimeType = mimeType;
/*     */   }
/*     */   
/*     */   public String getAuthor() {
/*  75 */     return this.mAuthor;
/*     */   }
/*     */   
/*     */   public void setAuthor(String a) {
/*  79 */     this.mAuthor = a;
/*     */   }
/*     */   
/*     */   public MailItem.Type getItemType() {
/*  83 */     return this.type;
/*     */   }
/*     */   
/*     */   public void setItemType(MailItem.Type type) {
/*  87 */     this.type = type;
/*     */   }
/*     */   
/*     */   public String getDescription() {
/*  91 */     return this.mDescription;
/*     */   }
/*     */   
/*     */   public void setDescription(String d) {
/*  95 */     this.mDescription = d;
/*     */   }
/*     */   
/*     */   public boolean isDescriptionEnabled() {
/*  99 */     return this.mDescEnabled;
/*     */   }
/*     */   
/*     */   public void setDescriptionEnabled(boolean descEnabled) {
/* 103 */     this.mDescEnabled = descEnabled;
/*     */   }
/*     */   
/*     */   public void setDocument(ParsedDocument doc) {
/* 107 */     setFilename(doc.getFilename());
/* 108 */     setMimeType(doc.getContentType());
/* 109 */     setAuthor(doc.getCreator());
/* 110 */     setDescription(doc.getDescription());
/* 111 */     setDescriptionEnabled(doc.isDescriptionEnabled());
/*     */   }
/*     */   
/*     */   protected String getPrintableData() {
/* 115 */     return "uuid=" + this.mUuid + ", " + super.getPrintableData();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException
/*     */   {
/* 120 */     out.writeUTF(this.mFilename);
/* 121 */     out.writeUTF(this.mMimeType);
/* 122 */     out.writeUTF(this.mAuthor);
/* 123 */     out.writeByte(this.type.toByte());
/* 124 */     if (getVersion().atLeast(1, 29)) {
/* 125 */       out.writeUTF(this.mDescription);
/*     */     }
/* 127 */     if (getVersion().atLeast(1, 31)) {
/* 128 */       out.writeBoolean(this.mDescEnabled);
/*     */     }
/* 130 */     if (getVersion().atLeast(1, 37)) {
/* 131 */       out.writeUTF(this.mUuid);
/*     */     }
/* 133 */     super.serializeData(out);
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException
/*     */   {
/* 138 */     this.mFilename = in.readUTF();
/* 139 */     this.mMimeType = in.readUTF();
/* 140 */     this.mAuthor = in.readUTF();
/* 141 */     this.type = MailItem.Type.of(in.readByte());
/* 142 */     if (getVersion().atLeast(1, 29)) {
/* 143 */       this.mDescription = in.readUTF();
/*     */     }
/* 145 */     if (getVersion().atLeast(1, 31)) {
/* 146 */       this.mDescEnabled = in.readBoolean();
/*     */     } else {
/* 148 */       this.mDescEnabled = true;
/*     */     }
/* 150 */     if (getVersion().atLeast(1, 37)) {
/* 151 */       this.mUuid = in.readUTF();
/*     */     }
/* 153 */     super.deserializeData(in);
/*     */   }
/*     */   
/*     */   public void redo() throws Exception
/*     */   {
/* 158 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/*     */     try {
/* 160 */       ParsedDocument pd = new ParsedDocument(getAdditionalDataStream(), this.mFilename, this.mMimeType, System.currentTimeMillis(), this.mAuthor, this.mDescription, this.mDescEnabled);
/*     */       
/* 162 */       mbox.createDocument(getOperationContext(), getFolderId(), pd, this.type, getFlags());
/*     */     } catch (MailServiceException e) {
/* 164 */       if (e.getCode() == "mail.ALREADY_EXISTS") {
/* 165 */         mLog.info("Document " + getMessageId() + " is already in mailbox " + mbox.getId());
/* 166 */         return;
/*     */       }
/* 168 */       throw e;
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/SaveDocument.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */